/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.pagequery;

/**
 * A sorter entry to present query key and query type.
 * 
 * @author liyuliang
 *
 */
public class SortEntry implements Comparable<SortEntry> {

  /**
   * ORDER ASC
   */
  public static final String ASC = "asc";

  /**
   * ORDER DESC
   * 
   */
  public static final String DESC = "desc";

  /**
   * Input key
   */
  private String key;

  /**
   * Input type
   */
  private String type;

  /**
   * Query key, default equals key
   */
  private String queryKey;

  /**
   * Query type, default equals type
   */
  private String queryType;

  private long seq;

  public SortEntry(String key, String type) {
    this.key = key;
    this.type = type;
  }

  public SortEntry(String key, long seq, String type) {
    this.key = key;
    this.type = type;
    this.seq = seq;
  }

  public String getKey() {
    return key;
  }

  public void setKey(String key) {
    this.key = key;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public String getQueryKey() {
    if (queryKey == null) {
      return key;
    }
    return queryKey;
  }

  public void setQueryKey(String queryKey) {
    this.queryKey = queryKey;
  }

  public String getQueryType() {
    if (queryType == null) {
      if (ASC.equals(type)) {
        return ASC;
      } else {
        return DESC;
      }
    }
    return queryType;
  }

  public void setQueryType(String queryType) {
    this.queryType = queryType;
  }

  public long getSeq() {
    return seq;
  }

  public void setSeq(long seq) {
    this.seq = seq;
  }

  @Override
  public int compareTo(SortEntry o) {
    if (o.getSeq() == this.getSeq()) {
      return 0;
    }
    if (this.getSeq() > o.getSeq()) {
      return 1;
    }
    return -1;
  }
  
  @Override
  public boolean equals(Object that) {
    return this == that;
  }



}
